package com.atguigu.wordcount.sortbean;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @ClassName SortMapper
 * @DeScription SortMapper
 * @Author 剧情再美终是戏
 * @Date 2019/11/19 9:26
 * @Version 1.0
 **/
public class SortMapper extends Mapper<LongWritable, Text, FlowBean, NullWritable> {

    private FlowBean out_key = new FlowBean();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] split = value.toString().split("\t");
        out_key.setPhnoeNum(split[1]);
        out_key.setUploadSum(Long.parseLong(split[split.length - 2]));
        out_key.setDownSum(Long.parseLong(split[split.length - 1]));
        out_key.setTotal(out_key.getDownSum() + out_key.getUploadSum());
        context.write(out_key, NullWritable.get());
    }
}
